import Vue from "vue";
import Vuex from "vuex";
import todo from "./todo"
import createPersistedState from "vuex-persistedstate";
import SecureLS from "secure-ls";  // npm install secure-ls -S
const ls = new SecureLS({ isCompression: false });

Vue.use(Vuex);

// const noUsePlugin = store => {
//   console.log(store)
//   store.replaceState(JSON.parse(localStorage.getItem('todo')))
//
//
//   store.subscribe((mutation, state) => {
//     console.log(mutation, state)
//     localStorage.setItem('todo', JSON.stringify(state))
//   })
// }


export default new Vuex.Store({
  actions: {},
  modules: {
    todo
  },
  plugins: [createPersistedState({    // 使用插件对vuex中的内容进行持久化
    storage: {
      getItem: (key) => ls.get(key),    // 对持久化的内容进行加密
      setItem: (key, value) => ls.set(key, value),
      removeItem: (key) => ls.remove(key),
    },
  })]
});
